package com.situ.hotel.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import com.situ.hotel.interceptor.AdminInterceptor;
import com.situ.hotel.interceptor.UserInterceptor;

@Configuration
public class WebConfig implements WebMvcConfigurer {

	@Value("${upload.path}")
	private String path;

	@Autowired
	private AdminInterceptor adminInterceptor;
	
	
	@Autowired
	private UserInterceptor userInterceptor;

	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		// TODO Auto-generated method stub
		// WebMvcConfigurer.super.addResourceHandlers(registry);
		registry.addResourceHandler("/upload/**").addResourceLocations("file:" + path);
	}
	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		registry.addInterceptor(adminInterceptor).addPathPatterns("/**").excludePathPatterns(
				"/admin/login.html","/api/admin/**","/layui/**",
				"/user/login.html","/api/user/login",
				"/user/reg.html","/api/user/reg",
				"/user/index.html",
				"/user/order.html","/user/myorder.html","/user/center.html",
				"/api/user/logout","/api/user/loginUser",
				"/api/room/user/**", "/api/order/user/**",
				"/error"
				);
		registry.addInterceptor(userInterceptor).addPathPatterns(
				"/user/index.html",
				"/user/order.html","/user/myorder.html","/user/center.html",
				"/api/user/logout","/api/user/loginUser",
				"/api/user/logout","/api/user/loginUser",
				"/api/room/user/**","/api/order/user/**"
				);
	}

}
